
# Definition for singly-linked list.
class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next
class Solution:
    def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode:
        list1=[]
        list2=[]
        while l1:
            list1.append(l1.val)
            l1=l1.next
        while l2:
            list2.append(l2.val)
            l2=l2.next
        print(list1)
        print(list2)
        a = max(len(list1), len(list2))
        # a =  len(list1) if len(list1) > len(list2) else len(list2)
        list3=[]
        b = 0
        for i in range(a):
            list3.append((list1[i]+list2[i])%10+b)
            b=(list1[i]+list2[i])//10
        print(list3)

        m = ListNode(0)
        n = m
        for i in range(len(list3)):
            n.next=ListNode(list3[i])
            n = n.next
        return m.next







if __name__ == '__main__':
    s = Solution()
    a = ListNode(2, ListNode(4, ListNode(3)))
    b = ListNode(5, ListNode(6, ListNode(4)))
    print(s.addTwoNumbers(a, b))